﻿using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace QBZ.Evaluation.Repositories.Migrations
{
    public partial class fore : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "tb_level",
                columns: table => new
                {
                    LevelId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    LevelName = table.Column<string>(maxLength: 100, nullable: true),
                    LevelDescription = table.Column<string>(maxLength: 500, nullable: true),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_level", x => x.LevelId);
                });

            migrationBuilder.CreateTable(
                name: "tb_role",
                columns: table => new
                {
                    RoleId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    RoleName = table.Column<string>(maxLength: 100, nullable: true),
                    RoleDescription = table.Column<string>(maxLength: 500, nullable: true),
                    RoleIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_role", x => x.RoleId);
                });

            migrationBuilder.CreateTable(
                name: "tb_session",
                columns: table => new
                {
                    SessionId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    SessionName = table.Column<string>(maxLength: 100, nullable: false),
                    SessionStartTime = table.Column<DateTime>(nullable: false),
                    SessionEndTime = table.Column<DateTime>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_session", x => x.SessionId);
                });

            migrationBuilder.CreateTable(
                name: "tb_skillParent",
                columns: table => new
                {
                    SkillParentId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    SkillParentName = table.Column<string>(maxLength: 100, nullable: false),
                    SkillParentDescription = table.Column<string>(maxLength: 500, nullable: true),
                    SkillParentIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_skillParent", x => x.SkillParentId);
                });

            migrationBuilder.CreateTable(
                name: "tb_levelChild",
                columns: table => new
                {
                    LevelChildId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    LevelId = table.Column<int>(nullable: false),
                    RoleChildName = table.Column<string>(maxLength: 100, nullable: true),
                    LevelChildDescription = table.Column<string>(maxLength: 500, nullable: true),
                    LevelChildInt = table.Column<int>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_levelChild", x => x.LevelChildId);
                    table.ForeignKey(
                        name: "FK_tb_levelChild_tb_level_LevelId",
                        column: x => x.LevelId,
                        principalTable: "tb_level",
                        principalColumn: "LevelId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_roleChild",
                columns: table => new
                {
                    RoleChildId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    RoleId = table.Column<int>(nullable: false),
                    RoleChildName = table.Column<string>(maxLength: 100, nullable: true),
                    RoleChildDescription = table.Column<string>(maxLength: 500, nullable: true),
                    RoleChildLevel = table.Column<int>(nullable: false),
                    RoleChildIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_roleChild", x => x.RoleChildId);
                    table.ForeignKey(
                        name: "FK_tb_roleChild_tb_role_RoleId",
                        column: x => x.RoleId,
                        principalTable: "tb_role",
                        principalColumn: "RoleId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_skill",
                columns: table => new
                {
                    SkillId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    SkillParentId = table.Column<int>(nullable: false),
                    SkillName = table.Column<string>(maxLength: 50, nullable: true),
                    SkillDescription = table.Column<string>(maxLength: 500, nullable: true),
                    SkillIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_skill", x => x.SkillId);
                    table.ForeignKey(
                        name: "FK_tb_skill_tb_skillParent_SkillParentId",
                        column: x => x.SkillParentId,
                        principalTable: "tb_skillParent",
                        principalColumn: "SkillParentId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_user",
                columns: table => new
                {
                    UserId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    UserName = table.Column<string>(maxLength: 50, nullable: false),
                    UserNick = table.Column<string>(maxLength: 50, nullable: true),
                    UserPassword = table.Column<string>(maxLength: 32, nullable: true),
                    UserEmail = table.Column<string>(maxLength: 50, nullable: true),
                    UserPhone = table.Column<string>(maxLength: 50, nullable: true),
                    IsDelete = table.Column<bool>(nullable: false),
                    RoleChildId = table.Column<int>(nullable: false),
                    UserLevel = table.Column<int>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_user", x => x.UserId);
                    table.ForeignKey(
                        name: "FK_tb_user_tb_roleChild_RoleChildId",
                        column: x => x.RoleChildId,
                        principalTable: "tb_roleChild",
                        principalColumn: "RoleChildId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_skillChild",
                columns: table => new
                {
                    SkillChildId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    SkillId = table.Column<int>(nullable: false),
                    SkillChildName = table.Column<string>(maxLength: 50, nullable: true),
                    SkillChildDescription = table.Column<string>(maxLength: 500, nullable: true),
                    SkillChildIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_skillChild", x => x.SkillChildId);
                    table.ForeignKey(
                        name: "FK_tb_skillChild_tb_skill_SkillId",
                        column: x => x.SkillId,
                        principalTable: "tb_skill",
                        principalColumn: "SkillId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_evaluation",
                columns: table => new
                {
                    EvaluationId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    EvaluationFrom = table.Column<int>(nullable: false),
                    EvaluationTo = table.Column<int>(nullable: false),
                    LevelInt = table.Column<int>(nullable: false),
                    SessionId = table.Column<int>(nullable: false),
                    SkillChildId = table.Column<int>(nullable: false),
                    EvaluationIsDelete = table.Column<bool>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_evaluation", x => x.EvaluationId);
                    table.ForeignKey(
                        name: "FK_tb_evaluation_tb_user_EvaluationFrom",
                        column: x => x.EvaluationFrom,
                        principalTable: "tb_user",
                        principalColumn: "UserId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_tb_evaluation_tb_session_SessionId",
                        column: x => x.SessionId,
                        principalTable: "tb_session",
                        principalColumn: "SessionId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_tb_evaluation_tb_skillChild_SkillChildId",
                        column: x => x.SkillChildId,
                        principalTable: "tb_skillChild",
                        principalColumn: "SkillChildId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "tb_roleSkill",
                columns: table => new
                {
                    RoleSkillId = table.Column<int>(nullable: false)
                        .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
                    RoleChildId = table.Column<int>(nullable: false),
                    LevelChildId = table.Column<int>(nullable: false),
                    SkillChildId = table.Column<int>(nullable: false),
                    CreateOn = table.Column<DateTime>(nullable: false),
                    CreateBy = table.Column<int>(nullable: false),
                    UpdateOn = table.Column<DateTime>(nullable: true),
                    UpdateBy = table.Column<int>(nullable: true),
                    TimeStamp = table.Column<byte[]>(rowVersion: true, nullable: true),
                    Guid = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tb_roleSkill", x => x.RoleSkillId);
                    table.ForeignKey(
                        name: "FK_tb_roleSkill_tb_levelChild_LevelChildId",
                        column: x => x.LevelChildId,
                        principalTable: "tb_levelChild",
                        principalColumn: "LevelChildId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_tb_roleSkill_tb_roleChild_RoleChildId",
                        column: x => x.RoleChildId,
                        principalTable: "tb_roleChild",
                        principalColumn: "RoleChildId",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_tb_roleSkill_tb_skillChild_SkillChildId",
                        column: x => x.SkillChildId,
                        principalTable: "tb_skillChild",
                        principalColumn: "SkillChildId",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_tb_evaluation_EvaluationFrom",
                table: "tb_evaluation",
                column: "EvaluationFrom");

            migrationBuilder.CreateIndex(
                name: "IX_tb_evaluation_SessionId",
                table: "tb_evaluation",
                column: "SessionId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_evaluation_SkillChildId",
                table: "tb_evaluation",
                column: "SkillChildId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_levelChild_LevelId",
                table: "tb_levelChild",
                column: "LevelId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_roleChild_RoleId",
                table: "tb_roleChild",
                column: "RoleId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_roleSkill_LevelChildId",
                table: "tb_roleSkill",
                column: "LevelChildId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_roleSkill_RoleChildId",
                table: "tb_roleSkill",
                column: "RoleChildId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_roleSkill_SkillChildId",
                table: "tb_roleSkill",
                column: "SkillChildId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_skill_SkillParentId",
                table: "tb_skill",
                column: "SkillParentId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_skillChild_SkillId",
                table: "tb_skillChild",
                column: "SkillId");

            migrationBuilder.CreateIndex(
                name: "IX_tb_user_RoleChildId",
                table: "tb_user",
                column: "RoleChildId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "tb_evaluation");

            migrationBuilder.DropTable(
                name: "tb_roleSkill");

            migrationBuilder.DropTable(
                name: "tb_user");

            migrationBuilder.DropTable(
                name: "tb_session");

            migrationBuilder.DropTable(
                name: "tb_levelChild");

            migrationBuilder.DropTable(
                name: "tb_skillChild");

            migrationBuilder.DropTable(
                name: "tb_roleChild");

            migrationBuilder.DropTable(
                name: "tb_level");

            migrationBuilder.DropTable(
                name: "tb_skill");

            migrationBuilder.DropTable(
                name: "tb_role");

            migrationBuilder.DropTable(
                name: "tb_skillParent");
        }
    }
}
